namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using System.Linq;
    
    public sealed class MissileOptimal<T> : FeatureBase<object>
    {
        public MissileOptimal(){}

        public MissileOptimal(T value) 
            : base(value){ }

        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Optimal range"; }
        }

        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup { get { return FeatureGroupsEnum.Specific; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.MissileOptimal; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_meters; } }

        public override bool IsRounded
        {
            get { return true; }
        }

        public override void SetModifiedValue(Contracts.Interfaces.IAgent agent, Contracts.Interfaces.IRobot robot)
        {
            if(agent ==null || robot ==null) return;

            
            double temp = (double) Value * (1 + (
                // Extension bonus
                agent.Extensions.SumModifiersValues(FeatureTypesEnum.Ammo, this.FeatureType) 
                // Robot modifiers
                + robot.Modifiers.SumModifiersValues(agent.Extensions,FeatureTypesEnum.Ammo,this.FeatureType))
                // Range extender module modifiers
                + robot.Modules.SumModifiersValues(FeatureTypesEnum.Ammo,this.FeatureType,ModuleGroupsEnum.RangeExtenders));

            ModifiedValue = IsRounded
                                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                                : Math.Round(temp, 2);

        }
    }
}